from django.db import models
import datetime
from typing import Iterable


# sqlmap数据库
class inject_data(models.Model):
    taskid = models.CharField(max_length=50)
    packet = models.TextField(default='')
    host = models.CharField(max_length=100)
    url = models.TextField(default='')
    dbms = models.TextField(default='')
    run_status = models.CharField(max_length=50, default='')
    status = models.CharField(max_length=10, default='0')
    parameter = models.CharField(max_length=20, default='')
    log_status = models.CharField(max_length=100, default='')
    api_address = models.CharField(max_length=100, default='')
    time = models.DateTimeField(auto_now=True)
    log = models.TextField(default='',null=True,blank=True)

    class Meta:
        permissions  = (
            ("display_sqli","展示被动注入的页面"),
            ("start_sqlmap","开始SQLMAP注入"),
            ("get_inject_data","获取sqlmap注入的数据"),
            ("update_auth","更新cookie的有效性"),
            ("check_log","查看sqlmap扫描的实时日志"),
            ("check_nlog","查看sqlmap扫描的最终日志"),
            ("check_data","查看sqlmap注入的数据包"),
            ("start_sqlmap_api","启动SQLMAP的API"),
            ("resart_injection_api","对单一数据包重新SQL注入"),
        )


# mimt过滤重复的数据
class filter_data(models.Model):
    host = models.CharField(max_length=100)
    data_packet = models.TextField()
    url = models.CharField(max_length=500)
    parm = models.TextField()
    status = models.CharField(max_length=10, default='0')
    taskid = models.CharField(max_length=100, default='')

    class Meta:
        permissions  = (
            ("filter_packect","过滤数据包"),
        )

# mimt所有代理数据
class proxy_data(models.Model):
    host = models.TextField(default='')
    url = models.TextField(default='')
    method = models.CharField(max_length=20, default='')
    request_headers = models.TextField(default='')
    scheme = models.TextField(default='')
    path = models.TextField(default='')
    request_cookies = models.TextField(default='')
    #port = models.CharField(max_length=20, default='')
    status_code = models.CharField(max_length=20, default='')
    response_headers = models.TextField(default='')
    response_content = models.TextField(default='')
    date = models.DateTimeField(auto_now=True)
    request_content = models.TextField()
    ip = models.GenericIPAddressField(default='0.0.0.0')
    http_version = models.CharField(max_length=20)


    class Meta:
        permissions  = (
            ("proxy_index","展示代理抓包的页面"),
            ("starting_proxy","启动mitmproxy进行代理监听"),
            ("display_proxy_data","展示全部代理数据包的信息"),
            ("check_filter_data","展示过滤之后的数据包"),

        )



# class sqlmap_log(models.Model):
#     taskid = models.CharField(max_length=100)
#     log = models.TextField(default='')





class auth_filter_raw(models.Model):
    host = models.CharField(max_length=100)
    path = models.CharField(max_length=100)
    method = models.CharField(max_length=10)
    url = models.TextField(blank=True,null=True)
    request_headers = models.TextField(default='')
    post_parm = models.TextField(blank=True,null=True)
    cookies = models.TextField(blank=True,null=True)
    get_parm = models.TextField(blank=True,null=True)
    cookies_status = models.CharField(max_length=100)
    get_list = models.TextField()
    post_list = models.TextField



    # cookieA_status = models.CharField(max_length=10,blank=True,null=True)
    # cookieB = models.TextField(blank=True,null=True)
    # cookieB_status = models.CharField(max_length=10,blank=True,null=True)


class authdata(models.Model):
    host = models.CharField(max_length=100)
    path = models.CharField(max_length=100)
    method = models.CharField(max_length=100)
    getparm = models.TextField()
    postparm = models.TextField()
    headers = models.TextField()
    cookies = models.TextField()


class authresult(models.Model):
    raw = models.ForeignKey(auth_filter_raw,on_delete=models.CASCADE)
    parm = models.CharField(max_length=100)
    result = models.CharField(max_length=10)